package com.cloudcc.mobile.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.cloudcc.cloudframe.model.Jxmedel;
import com.cloudcc.mobile.R;

public class listbrforeadapter extends BaseAdapter {
	private List<Jxmedel> data;
	private LayoutInflater inflater;

	// Context context;
	public listbrforeadapter(Context mContext, List<Jxmedel> data) {
		this.data = data;
		// context = mContext;
		this.inflater = LayoutInflater.from(mContext);

	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return data.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View view, ViewGroup arg2) {
		viewholder vholer = null;
		if (view == null) {
			vholer = new viewholder();

			view = inflater.inflate(R.layout.beforeitem, null);

			vholer.key = (TextView) view.findViewById(R.id.make_phone_tv_key);
			vholer.value = (TextView) view
					.findViewById(R.id.make_phone_tv_value);

			vholer.box = (CheckBox) view.findViewById(R.id.market_checkbox);
			view.setTag(vholer);
		} else {
			vholer = (viewholder) view.getTag();
		}
		if (data.size() < 1) {
			return view;
		}
		if ("true".equals(data.get(arg0).getValue()
				.substring(1, data.get(arg0).getValue().length() - 1))) {
			vholer.box.setVisibility(0);
			vholer.box.setChecked(true);
			vholer.value.setVisibility(View.GONE);
		} else if ("false".equals(data.get(arg0).getValue()
				.substring(1, data.get(arg0).getValue().length() - 1))) {
			vholer.box.setVisibility(0);
			vholer.box.setChecked(false);
			vholer.value.setVisibility(View.GONE);
		} else {
			vholer.box.setVisibility(View.GONE);
			vholer.value.setVisibility(View.VISIBLE);
		}
		vholer.key.setText(data.get(arg0).getName()
				.substring(1, data.get(arg0).getName().length() - 1));
		vholer.value.setText(data.get(arg0).getValue()
				.substring(1, data.get(arg0).getValue().length() - 1));

		return view;
	}

	public class viewholder {
		TextView key, value;
		CheckBox box;
	}

}
